#Chreamter OS Vision 1.0.0.3
#FStudio.io
#使用Apache 2.0开源

#需要的第三方库导入
from time import strftime,localtime,sleep  #用于get_localtime模块;sleep -> Seting
from os import system #系统终端调用
#时间系统
def get_localtime ():
    return strftime('%Y-%m-%d %H:%M:%S', localtime()) #strftime,localtime均来自time库
#日志系统
def log (msg,code):
    lf=open('./CHROS_log.log','a',encoding="utf-8")
    if '0' in code:
        if 'e' in code:
            lf.write('['+get_localtime()+']'+'输出错误:'+msg+'\n')
            lf.write('['+get_localtime()+']'+'错误:'+msg+'\n')
        elif 'w' in code:
            lf.write('['+get_localtime()+']'+'输出警告:'+msg+'\n')
            lf.write('['+get_localtime()+']'+'警告:'+msg+'\n')
        elif 'i' in code:
            lf.write('['+get_localtime()+']'+'输出:'+msg+'\n')
    elif '1' in code:
        lf.write('['+get_localtime()+']'+'User输入:'+msg+'\n')
    elif '2' in code:
        lf.write('['+get_localtime()+']'+'内部信息:'+msg+'\n')
    elif '3' in code:
        lf.write('['+get_localtime+']'+'安全拦截'+msg+'\n')
    lf.close()
#SelEngine 新的输出体验
def sel (msg,code='0i'):
    if '0' in code:
        if 'e' in code:
            print('\033[1,31,44mE:{}\033[0m'.format(msg))
            log(msg,'0e')
        elif 'w' in code:
            print('\033[1,33,44mW:{}\033[0m'.format(msg))
            log(msg,'0w')
        elif 'i' in code:
            print('{}'.format(msg))
            log(msg,'0i')
    elif '1' in code:
        if 'e' in code:
            print('\033[4,31mE:{}\033[0m'.format(msg))
            log(msg,'0e')
        elif 'w' in code:
            print('\033[33mW:{}\033[0m'.format(msg))
            log(msg,'0w')
        elif 'i' in code:
            print('\033[4mI:{}\033[0m'.format(msg))
            log(msg,'0i')
def seli (poress=''): 
    t=input(poress)
    log(t,1)
#初始化程序(版本1.0.0.0)
def seting_get_csv ():
    csvf=open('./Seting.csv','r')
    lis=csvf.read().strip('\n').split(",")
    csvf.close()
    return csvf
def seting_save_csv (save_list):
    csvf=open('./Seting.csv','w')
    csvf.write(",".join(save_list)+"\n")
    csvf.close()
def init ():
    system('title Chreamter OS Vision 1.0.0.0')
    info=seting_get_csv()
    system('color {}'.format(str(info[0])))
    global temp,tvr_info
    tvr_info=['chreoskrl','usertermessge','outcode']
    sel('Chreamter OS Vision 1.0.0.0')
    sel('2023 FStudio.io')
#系统工具集
#1.设置
def seting ():
    i1,i2 = 0,0
    setingf=seting_get_csv()
    sel('Chreamter 设置')
    i=0
    while i==0:
        i=0
        sel('选择设置:1.Terminal 设置 2.加速模式 3.Temp 设置 4.退出')
        text=seli('>')
        if text == '1':
            i2=0
            while i2 == 0:
                sel('Terminal设置 当前Terminal设置:{}'.format())
                sel('回车继续,输入"1"修改 Terminal设置')
                text=seli('>')
                if text == '':
                    i2=1
                elif text == '1':
                    check_text=['0','1','3','4','5','6','7','8','9',\
                        'a','b','b','d','e','f',\
                            'A','B','C','D','E','F']
                    if text[:1] in check_text and text[0:] in check_text:
                        sel('Terminal 设置已更改为{}'.format(text))
                        sleep(0.3)
                        setingf[0]=text
                    else:
                        sel('请重试!或查看PowerShell的color /?指令.')
                    i2=1
                else:
                    sel('请重试!输入错误.')
            i2=0
        elif text == '2':
            if setingf[1] == 1:
                sel('加速模式 处于 NO 状态')
            else:
                sel('加速模式 处于 OFF 状态')
            while i2 == 0:
                sel('回车继续,输入"1"修改 加速模式 设置')
                text=seli('>')
                if text == '':
                    i2=0
                elif text == '1':
                    if setingf[1] == 0:
                        print('''加速模式
                        |-------------------------------|
                        |                     NO ||||||||
                        |-------------------------------|
                        ''')
                        setingf[1]=1
                    else:
                        print('''加速模式
                        |-------------------------------|
                        |||||||| OFF                    |
                        |-------------------------------|
                        ''')
                        setingf[1]=0
                    i2=1
            i2=0
        elif text == '3':
            if setingf[1] == 1:
                sel('Temp 处于 NO 状态')
            else:
                sel('Temp 处于 OFF 状态')
            while i2 == 0:
                sel('回车继续,输入"1"修改 Temp 设置')
                text=seli('>')
                if text == '':
                    i2=0
                elif text == '1':
                    if setingf[1] == 0:
                        print('''Temp
                        |-------------------------------|
                        |                     NO ||||||||
                        |-------------------------------|
                        ''')
                        setingf[1]=1
                    else:
                        print('''Temp
                        |-------------------------------|
                        |||||||| OFF                    |
                        |-------------------------------|
                        ''')
                        setingf[1]=0
                    i2=1
            i2=0
        elif text == '4':
            i=1
        else:
            sel('请重新输入!')
    seting_save_csv(setingf)

#2.Task Viewer (全部使用简称"Tvr")
def Tvr ():
    sel('Task Viewer 1.0.0.0')
    sel('进程')
    print('-'*25)
    for i in tvr_info:
        sel(i)
    print('-'*25)
#3.Help模块
def get_all_mager ():
    all_mgr=['about','seting','vision','']
    return all_mgr
def get_all_ser ():
    all_ser=['关于','设置','版本']
    return all_ser
def get_help():
    sel('Help----------帮助')
    print('-'*25)
    sell=get_all_mager()
    serr=get_all_ser()
    new=[]
    s=0
    for i in sell:
        e=len(i)
        rp='-'*(15-e)
        sel('{}{}{}'.format(i,rp,serr[s]))
        s=s+1
    print('-'*25)            

#Main
def Main ():
    init()
    while True:
        text=seli('>>>')
        if text == 'help':
            help()
        elif text == 'seting':
            seting()
        elif text == 'about':
            seli('')
Main()